﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Project
{
    class Clients
    {
        private static string query;

        /*
         * The following function returns a datatable with all of 
         * the clients in the data source
         */
        public static DataTable showAllClients(){
            DataTable dt = new DataTable();
            query = "SELECT * FROM tbl_clients";
            try
            {
                dt = AdoHelper.ExecuteDataTable(query);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
            return dt;
        }
        /*
         * The following function returns a datatable with one 
         * client in the data source with the given argument
         * of his ID number, which is the primary Key for the Employee
         * table.
         */
        public static DataTable searchClient(string id)
        {
            DataTable dt = new DataTable();
            query = "SELECT * FROM tbl_clients WHERE fld_clientID Like '" + id + "'";
            try
            {
                dt = AdoHelper.ExecuteDataTable(query);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
            return dt;
        }
        /*
         * The following function adds a new client to the database 
         */
        public static void addClient(string id, string name, string lname, string address, string phone)
        {
            query = "INSERT INTO tbl_Clients VALUES('" + id + "', '" + name + "', '" + lname + "', '" + address + "', '" + phone + "')";
            AdoHelper.ExecuteNonQuery(query);
        }

        /*
         * The following function gets an update query that
         * contains the fields that the user would like to update
         * and updates them in the database.
         */
        public static void updateClient(string updateQuery)
        {
            AdoHelper.ExecuteNonQuery(updateQuery);
        }
    }
}
